/**
 * 定义实时数据模块
 */
(function(window, angular, undefined){
	var module = angular.module('water.apps.ws.dataMonitor.hourAlarm.hourAlarmDataManager', ['water.entity.houralarmdata']);
	
	module.controller('hourAlarmManagerController',function($rootScope,$scope,$waterDataCommon,$houralarmdataService){
		/**
		 * 报警类型
		 */
		$scope.alarmInfoTypeData=[];
		$scope.alarmInfoTypeData.push({"k":"allType","v":"全部"},{"k":"O","v":"超标"},{"k":"D","v":"异常"});
		/**
		 * 超标数据绑定
		 */
		$scope.alarmType="allType";
		/**
		 * 查询条件
		 */
		$scope.queryObject={};
		/**
		 * 查询数据
		 */
		$scope.AlarmInfoList=[];
		//监听左侧列表
	    $scope.$on('dataPramChanged', function(event, data) {
	    	if($scope.firstQuery){
				$scope.allStationSelected = true;
			}
			else{
				$scope.allStationSelected = false;
			}
			$scope.firstQuery = false;
	    	$wdp.viewValue.wwtpDetailParm = data;
			$scope.STATION_NAME=$wdp.viewValue.wwtpDetailParm.STATION_NAME;
			$scope.STATION_ID = $wdp.viewValue.wwtpDetailParm.STATION_ID;
			$("#wsclcname li[orgid='"+1+"']").removeClass('selected');
			$("#wsclcname li[orgid='"+0+"']").addClass('selected');
			$scope.onQueryClick();
	    });
		/**
		 * 站点选择
		 */
		$scope.getStationname=function(orgid){
			if(orgid=="0"){
				$("#wsclcname li[orgid='"+1+"']").removeClass('selected');
				$("#wsclcname li[orgid='"+0+"']").addClass('selected');
				$scope.allStationSelected=false;
			}
            if(orgid=="1"){
            	$("#wsclcname li[orgid='"+0+"']").removeClass('selected');
            	$("#wsclcname li[orgid='"+1+"']").addClass('selected');
            	$scope.queryObject.STATION_ID="";
            	$scope.queryObject.WWTP_ID="";
            	$scope.allStationSelected=true;
			}
		};
		
		/**
		 * 查询
		 */
		$scope.onQueryClick=function(){
			$scope.AlarmInfoList=[]
			$scope.queryObject.OVER_FLAG=$scope.alarmType;
			$scope.queryObject.waterType=getWaterType();
			if($scope.allStationSelected == true){
				   $scope.queryObject.MN = null;
			 }else{
					$scope.queryObject.MN = $wdp.viewValue.wwtpDetailParm.MN;
		   }
			$houralarmdataService.getList($scope.queryObject).then(function(d){
				if(d.data.length>0){
					var obj;
					for(var i=0;i<d.data.length;i++){
						obj=d.data[i];
						if(obj.PARMNAME=="phtem"){
							
						}
						else{
							$scope.AlarmInfoList.push(obj);
						}
					}
				}
				else{
					$scope.AlarmInfoList=d.data;	
				}
				
			});
			
		};
		/**
		 * 导出报表
		 */
		$scope.onExportExcelClick=function(){
			$houralarmdataService.ExportExcel($scope.queryObject);
		};
		/**
		 * 导出报警报告
		 */
		$scope.onExportWordClick=function(data){
			var queryString = $waterDataCommon.jsonTostring(data);
			window.open(getBasePath()+"/HourAlarmData/ExportWord.do?"+queryString);
		};
		/**
		 * 导出报警报告
		 */
		$scope.onMonthClick=function(data){
			$waterDataCommon.post("/HourAlarmData/CreateMonthData.do",data,function(d){
				
			})
		};
		//初始化日期
		$scope.initQuery = function(){
			var nowDate = new Date();
			var month;
			var day;
			var curMonthDays = new Date(nowDate.getFullYear(), (nowDate.getMonth()), 0).getDate();//获取当月有多少天
			if(nowDate.getDate()-1==0){
				month=nowDate.getMonth();
				day=curMonthDays;
			}else{
				month=nowDate.getMonth()+1;
				day=nowDate.getDate();
			}
			if(month<10){
				month="0"+month;
			}
			if(day<10){
				day="0"+day;
			}
			$scope.queryObject.start=nowDate.getFullYear()+"-"+month+"-"+day;
		}
		$scope.initQuery();
	});
}(window, angular));	